home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: artemis.sto.fdata.se!news
- From: Niklas Mellin <niklas.mellin@sto.fdata.se>
- Subject: Re: Is this code valid?
- Sender: news@artemis.sto.fdata.se (UseNet NetNews)
- Message-ID: <30F531DB.D8A@sto.fdata.se>
- Date: Thu, 11 Jan 1996 15:50:51 GMT
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <30F3E42D.74BA@sto.fdata.se> <30F43E85.7C9B@bangate.compaq.com>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0b4 (WinNT; I)
- Organization: WM-data F÷rsvarsdata AB, Sweden
-
- Saurabh Dixit wrote:
- >
- > Niklas Mellin wrote:
- > >
- > > class X
- > > {
- > > public:
- > > class Y;
- > > };
- > >
- > > class X::Y
- > > {
- > > };
- > >
- > > int main(int, char* [])
- > > {
- > > throw X::Y();
- > > return 0;
- > > }
- > >
- > > It doesn't matter if the throw statement is in main or in
- > > some other function, and it makes no difference if there
- > > is a catch statement.
- > >
- > > When linking the code above in Borland C++ 4.0 the ide
- > > crashes killing windows too (it took me a while to
- > > isolate the problem).
- > >
- > > Borland 4.5 doesn't crash but reports: "Internal error..."
- > > some number.
- > >
- > > My question: Is it allowed to throw objects of nested
- > > classes?
- > >
- > > ---
- > > Niklas Mellin
- >
- > Though I wouldn't expect a compiler to crash when it
- > encounters possible bad code, I don't see what you are
- > trying to throw.
- > Don't you need an object to throw?
-
- Yes.
-
- > In the statement
- > throw X::Y() where is the object?
-
- Right in front of you. X::Y() is the default constructor
- of Y, so a temporary object of that class is created, and
- it is that temporary that is thrown. I believe this is a
- standard technique.
-
- ---
- Niklas Mellin
-